﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Hive.Core.Common.Shell;

namespace Hive.Core.Model.Commands
{
    /// <summary>
    /// Creates a new hive.
    /// </summary>
    public class CreateHiveCommand : Command
    {
        private readonly DirectoryInfo hiveDirectory;

        /// <summary>
        /// Initializes the command.
        /// </summary>
        /// <param name="hiveDirectory">The hive directory.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="hiveDirectory"/> is null.</exception>
        public CreateHiveCommand(DirectoryInfo hiveDirectory)
        {
            if (hiveDirectory == null)
                throw new ArgumentNullException("hiveDirectory");

            this.hiveDirectory = hiveDirectory;
        }

        /// <inheritdoc />
        protected override CommandExitCode ExecuteImpl(IHiveManager hiveManager, IShell shell)
        {
            var sourceRepositoryConfiguration = new SubversionSourceRepositoryConfiguration();
            var binaryRepositoryConfiguration = new ArchivedBinaryRepositoryConfiguration();
            var hiveConfiguration = new HiveConfiguration(sourceRepositoryConfiguration, binaryRepositoryConfiguration);

            hiveManager.Create(hiveDirectory, hiveConfiguration);
            return CommandExitCode.Success;
        }
    }
}
